package com.hfy.kandian.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import redis.clients.jedis.Jedis;

import javax.servlet.http.HttpSession;


/**
 * 测试控制器
 * */

@RestController
@RequestMapping("/test")
public class TestController {
    @ApiOperation(value ="测试redis:查")
    @GetMapping("/get/{key}")
    public String testRedisFind(@PathVariable String key){
        Jedis jedis = new Jedis("47.96.103.214",6379);
        jedis.auth("123456");
        System.out.println("这是一个日志查");
        return jedis.get(key);
    }

    @ApiOperation(value ="测试redis：增改")
    @GetMapping("/set/{key}/{value}")
    public String testRedisInsertChange(@PathVariable String key,@PathVariable String value){
        Jedis jedis = new Jedis("47.96.103.214",6379);
        jedis.auth("123456");
        System.out.println("这是一个日志增改");
        return jedis.set(key,value);
    }

    @ApiOperation(value = "session登录测试")
    @GetMapping("/sessionLoginTest/{username}/{userpwd}")
    public String testLoginSession(@PathVariable String username,@PathVariable String userpwd,HttpSession httpSession){
        httpSession.setAttribute("username",username);
        httpSession.setAttribute("userpwd",userpwd);
        return "成功";
    }
    @ApiOperation(value = "session校验测试")
    @GetMapping("/sessionTest")
    public String sessionTest(HttpSession httpSession){
        return httpSession.getAttribute("username").toString()+"--"+httpSession.getAttribute("userpwd").toString();
    }

}
